let span = document.querySelector(".span");
let fixation = document.querySelector('.fixation');
span.onclick=function(){
    fixation.style.display = "none"
}

$(".btn").on("click",function(){
    $.ajax({
        url:"http://localhost:4999/api",
        data:{
            type:"login",
            username:$("#username").val(),
            password:$("#password").val()
        },
        success:res=>{
            console.log(res)
            res = JSON.parse(res);
            if(res.code === 0){
                if(confirm("用户名不存在，是否跳转到注册")){
                    location.href = "./register.html"
                }
            }else if(res.code === 1){
                alert(res.title);
                $("#password").val("");
                $("#password")[0].focus();
            }else if(res.code === 2){
                if(confirm("登录成功，是否跳转到首页")){
                    location.href = "./index.html"
                }
                sessionStorage.setItem("isLogin",JSON.stringify({
                    code:"OK",
                    name:res.data
                }))
            }
        }
    })
})